﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Security;
using PBDesk.Business.Gigya;

namespace CMS.PBDesk.Business.UserManager
{
    public class UserManager
    {
        public static UserCreationStatus CreateUser(string gigyaUid, string email)
        {
            UserCreationStatus success = UserCreationStatus.failure;
            MembershipCreateStatus status = MembershipCreateStatus.UserRejected;
            bool result = false;
            Membership.CreateUser(email, "Y#zx8A72^d", email, null, null, true, out status);

            if (status == MembershipCreateStatus.Success)
            {
                result = GigyaHelper.RegisterGigyaUser(gigyaUid, email);
                if (result == false)
                {
                    success = UserCreationStatus.GigyaRegistrationFailure;
                }
                else
                {
                    success = UserCreationStatus.success;
                }
            }
            else
            {
                success = UserCreationStatus.UmbracoMembershipFailure;
            }

            return success;
        }
    }
}
